<template>

  <el-select
    v-model="professionsId"

    placeholder="请选择专业"
    filterable
    clearable
    :disabled="disabled"
  >
    <el-option
      v-for="dict in professionsList"
      :key="dict.id"
      :label="dict.professionName"
      :value="dict.id"
    />
  </el-select>


</template>

<script>
import common from "@/api/collegebase/common";

export default {
  name: "ProfessionsSelector",
  props: {
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    departmentId: {
      type: String,
      default: ''
    },
  }
  ,
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      professionsList: [],
      professionsId: '',
    };
  },

  created() {
  },

  watch: {
    professionsId(value) {
      this.$emit('change', value)
    },
    departmentId:{
      immediate:true,
      handler(newVal,oldVal){
        // console.log(newVal,oldVal)
        if(oldVal){
          this.professionsId = '';
        }else{
          this.professionsId = this.value;
        }

        this.getProfessionData(newVal);
      }
    },
    value(value) {
      // console.info("专业 执行value 操作：", value)
      this.professionsId = value;
    }
  },
  methods: {
    //获取学院
    async getProfessionData(departmentsId) {
      if (null == departmentsId || '' == departmentsId) {
        this.professionsList = []

        return;
      }
      const departmentsList = await common.getProfessionsList(departmentsId);
      this.professionsList = departmentsList.data;
    },

    clear() {
      this.$emit("change", '')
    }


  }

}
</script>

